#pragma once
#include <cstdint>
#include <string>
typedef enum TIOSensorErr
{
    TIO_SENSOR_NONE_ERR = 0,
    TIO_SENSOR_DATA_ERR = 1,
    TIO_SENSOR_REC_ERR = 2,
} TIOSensorErr;

namespace rtdev {
class TIOSensor
{
public:
    static const uint16_t TIO_SENSOR_WATCDOG_COUNT = 10;
    static const uint16_t SNESOR_DATA_LENGTH = 12;

public:
    TIOSensor();
    virtual ~TIOSensor();
    virtual void update();
    void comm_read_sensor_data(uint8_t* buf, int len);
    TIOSensorErr getSensorError() const { return tio_sensor_err_; }

private:
    void check_alive();
    void keep_alive();

    bool alive_flag_ = false;
    bool sim_flag_ = false;
    uint32_t alive_watchdog_;  //通讯超时看门狗
private:
    uint32_t lowpass_filter_frq_ = 0;
    double last_sensor_data_[6] = {0.0};
    double sensor_data_[6] = {};
    double sensor_raw_data_[6] = {};
    TIOSensorErr tio_sensor_err_ = TIO_SENSOR_NONE_ERR;
    int32_t data_err_count_ = 0;

    void doFilt(const double* raw_data);
    int decodeSensor(uint8_t* buf, int len);
};
}  // namespace rtdev